const { checkLogin} = require("../../utils/util");
const db = wx.cloud.database();

// pages/snapshot/snapshot.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    approvedList:[],
    loading:true
  },

  onPullDownRefresh() {
    this.setData({
      approvedList: [],
      loading:false
    })
    this._index=0
    this.getData();
    wx.stopPullDownRefresh()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(app.globalData.userInfo);
    this._index=0
    this.getData()
  },
  //到底加载更多数据
  onReachBottom(){
    this.getData()
  },
  getData(){
    this.setData({
      loading: true
    })
    db.collection("snapShot").orderBy('time', 'desc').skip(this._index*6).limit(6).where({
      state: 1,
    }).get().then((res) => {
      console.log(res)
      if (res.data.length !== 0) {
        this.setData({
          approvedList: this.data.approvedList.concat(res.data)
        })
      }
      this._index++
      this.setData({
        loading: false
      })
    })

  },
  go(){
    checkLogin().then(()=>{
      wx.navigateTo({
        url: '../../otherTap/pages/makeSnapshot/makeSnapshot',
      })
    });
  },
  //跳转详情
  click(e){
    const item = e.currentTarget.dataset.item
    console.log(item);
    wx.navigateTo({
      url: `../snapShotDetail/snapShotDetail?_id=${item._id}&title=${'snapShot'}`,
    })
  },
})